#include "StdAfx.h"
#include "CommonFun.h"
//#include "OptionOpr.h"

CCommonFun::CCommonFun(void)
{
}

CCommonFun::~CCommonFun(void)
{
}

CString TracePlugin_Sim(DuiLib::CControlUI * pTraceInfo)
{
	CString strType = pTraceInfo->GetClass();
	CString strName = pTraceInfo->GetName();
	CString strText = pTraceInfo->GetText();
	const RECT & rect = pTraceInfo->GetPos();
	BOOL bIsVisable = pTraceInfo->IsVisible();

	CString strInfo;
	strInfo.Format(_T("	Type=%s,Name=%s,Text=%s,visable=%d,"),strType,strName,strText,bIsVisable);

	CString strSpecInfo;
	if(_T("ButtonUI") == strType)
	{
		DuiLib::CButtonUI * pButtonUI = static_cast<DuiLib::CButtonUI*>(pTraceInfo);
		strSpecInfo.Format(_T(",normalImage=%s,"),pButtonUI->GetNormalImage());
	}

	CString strRect;
	strRect.Format(_T("Rect;%d,%d,%d,%d\r\n"),rect.left,rect.top,rect.right,rect.bottom);
	return strInfo + strSpecInfo + strRect;
}

BOOL CheckNeedIsCContainerUI(DuiLib::CControlUI * pTraceInfo)
{
	CString strClassName = pTraceInfo->GetClass();
	if(_T("HorizontalLayoutUI") == strClassName ||\
		_T("VerticalLayoutUI") == strClassName ||\
		_T("TileLayoutUI") == strClassName ||\
		_T("List") == strClassName ||\
		_T("ContainerUI") == strClassName)
		return TRUE;
	return FALSE;
}

BOOL CCommonFun::TracePlugin_Child(DuiLib::CContainerUI * pTraceInfo,int loopCount)
{
	CString strInfo;
	CString strTemInfo;
	int i = 0;
	for (i = 0;i < loopCount;i++)
	{
		strTemInfo += _T("----->");
	} 

	for(i = 0;i < pTraceInfo->GetCount();i++)
	{
		strInfo = strTemInfo + TracePlugin_Sim(pTraceInfo->GetItemAt(i));
		OutputDebugString(strInfo);
//		PrintInfo(strInfo,i);
		if(CheckNeedIsCContainerUI(pTraceInfo->GetItemAt(i)))
			TracePlugin_Child((DuiLib::CContainerUI *)pTraceInfo->GetItemAt(i),loopCount + 1);
	}
	return TRUE;
}

BOOL CCommonFun::TracePlugin(DuiLib::CControlUI * pTraceInfo,int loopCount)
{

	OutputDebugString(_T("----------------------------------------------------------\r\n"));
	
	CString strClassName = pTraceInfo->GetClass();
	CString strTemInfo = TracePlugin_Sim(pTraceInfo);
	OutputDebugString(strTemInfo);
//	PrintInfo(strTemInfo,0);
	if(CheckNeedIsCContainerUI(pTraceInfo))
		TracePlugin_Child((DuiLib::CContainerUI *)pTraceInfo,loopCount + 1);

	OutputDebugString(_T("----------------------------------------------------------\r\n"));

	return TRUE;
}
